//
//  NaviVC.m
//  YueYueSpecailCarDriver
//
//  Created by 李亚军 on 17/2/28.
//  Copyright © 2017年 黄旺鑫. All rights reserved.
//

#import "NaviVC.h"
#import "NavigationMap.h"
#import <AMapNaviKit/AMapNaviKit.h>
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import <MBProgressHUD/MBProgressHUD.h>
#import <MBProgressHUD_QXUtils/MBProgressHUD_QXUtils-umbrella.h>
@interface NaviVC ()<AMapNaviDriveViewDelegate , AMapNaviDriveManagerDelegate , AMapNaviDriveDataRepresentable>





@end

@implementation NaviVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNaviMap];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}


/**
 初始化导航
 */
- (void)initNaviMap {
    
    // 导航
    [self initDriveManager];
    [self initDriveView];
    [self configDriveNavi];
}

- (void)monitorButAction:(UIButton *)sender {
    
    [self.driveManager startEmulatorNavi];
}

#pragma mark - 配置导航
/**
 创建 AMapNaviDriveManager
 */
- (void)initDriveManager
{
    if (self.driveManager == nil)
    {
        self.driveManager = [[AMapNaviDriveManager alloc] init];
        [self.driveManager setDelegate:self];
    }
}

/**
 创建 AMapNaviDriveView
 */
- (void)initDriveView
{
    if (self.driveView == nil)
    {
        self.driveView = [[AMapNaviDriveView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        
        if (self.orderStatusEnumCode == OrderStatusEnumCode_DriverSetOut_GoToPickUpPassengers) {
            
            [self.driveView setEndPointImage:[QXDriverConfiguration imageWithName:@"public_pic_qidian"]];
        }else {
            
            [self.driveView setEndPointImage:[QXDriverConfiguration imageWithName:@"public_pic_zhongdian"]];
        }
        
        [self.driveView setShowCamera:YES]; // 是否显示摄像头,默认YES
        [self.driveView setShowMode:(2)]; // 导航界面显示模式,默认AMapNaviDriveViewShowModeCarPositionLocked 1: 锁车状态 , 2: 全览状态 , 3: 普通状态
        [self.driveView setShowCompass:YES]; // 是否显示指南针,默认NO
        [self.driveView setShowTurnArrow:YES]; // 是否显示转向箭头,默认YES
        [self.driveView setShowCrossImage:YES]; // 是否显示路口放大图,默认YES
        [self.driveView setShowMoreButton:NO]; // 是否显示更多按钮,默认YES
        [self.driveView setShowTrafficBar:YES]; // 是否显示路况光柱,默认YES
        [self.driveView setShowUIElements:YES]; // 是否显示界面元素,默认YES
        [self.driveView setShowTrafficButton:YES]; // 是否显示实时交通按钮,默认YES
        [self.driveView setShowTrafficLayer:YES]; // 是否显示实时交通图层,默认YES
        [self.driveView setShowBrowseRouteButton:YES]; // 是否显示全览按钮,默认YES
        [self.driveView setShowStandardNightType:NO]; // 是否黑夜模式,默认NO
        [self.driveView setCameraDegree:0];
        [self.driveView setMapZoomLevel:12];
        [self.driveView setUserInteractionEnabled:YES];
        
        
        [self.driveView setDelegate:self];
    }
}

/**
 将 AMapNaviDriveView 与 AMapNaviManager 关联起来，并将 AManNaviDriveView 显示出来
 */
- (void)configDriveNavi
{
    [self.view addSubview:self.driveView];
    [self.driveManager addDataRepresentative:self.driveView];
    
    [self.driveView setMapZoomLevel:16.0];
    [self.driveView setCameraDegree:0.0];
    self.driveView.trackingMode = AMapNaviViewTrackingModeCarNorth;
    self.driveView.showMode = AMapNaviDriveViewShowModeCarPositionLocked;
    

    
    if (![self.driveManager startGPSNavi]) {
        
        [self.driveManager startGPSNavi];
    }else {
        
        [self.driveManager resumeNavi];
    }

}



#pragma mark - AMapNaviDriveViewDelegate
/**
 *  导航界面关闭按钮点击时的回调函数
 */
- (void)driveViewCloseButtonClicked:(AMapNaviDriveView *)driveView {
    
    if (self.closeAction) {
        self.closeAction();
    }
    [self.driveManager removeDataRepresentative:self];
    [self.driveManager removeDataRepresentative:self.driveView];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)dealloc
{
    NSLog(@"导航页面销毁了");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
